<?php

class MediaConfiguration
{
  const VERIFY_MIME_TYPE     = true;
  const MAX_UPLOAD_FILE_SIZE = 20981760;
  /**
   * Don't thumbnail an image if it will use too much working memory
   * Default is 50 MB if decompressed to RGBA form, which corresponds to
   * 12.5 million pixels or 3500x3500
   */
  const MAX_IMAGE_AREA       = 1.25e7;
  const MEDIATYPE_UNKNOWN    = 'UNKNOWN';     //unknown format
  const MEDIATYPE_BITMAP     = 'BITMAP';      //some bitmap image or image source (like psd, etc). Can't scale up.
  const MEDIATYPE_DRAWING    = 'DRAWING';     //some vector drawing (SVG, WMF, PS, ...) or image source (oo-draw, etc). Can scale up.
  const MEDIATYPE_AUDIO      = 'AUDIO';       //simple audio file (ogg, mp3, wav, midi, whatever)
  const MEDIATYPE_VIDEO      = 'VIDEO';       //simple video file (ogg, mpg, etc; no not include formats here that may contain executable sections or scripts!)
  const MEDIATYPE_MULTIMEDIA = 'MULTIMEDIA';  //Scriptable Multimedia (flash, advanced video container formats, etc)
  const MEDIATYPE_OFFICE     = 'OFFICE';      //Office Documents, Spreadsheets (office formats possibly containing apples, scripts, etc)
  const MEDIATYPE_TEXT       = 'TEXT';        //Plain text (possibly containing program code or scripts)
  const MEDIATYPE_EXECUTABLE = 'EXECUTABLE';  //binary executable
  const MEDIATYPE_ARCHIVE    = 'ARCHIVE';     //archive file (zip, tar, etc)
  
  protected static
    $mediaTypes         = array(),
    $majorMimes         = array(),
    $fileWhiteList      = array(),
    $fileBlackList      = array(),
    $imageMimeTypeList  = array(),
    $wellKnownMimeTypes = '',
    $wellKnownMimeInfo  = '';
  
  public static function setup()
  {
    self::$mediaTypes    = array
                           (
                             'AU' => 'AUDIO',
                             'AR' => 'ARCHIVE',
                             'BI' => 'BITMAP',
                             'DR' => 'DRAWING',
                             'EX' => 'EXECUTABLE',
                             'MU' => 'MULTIMEDIA',
                             'OF' => 'OFFICE',
                             'TE' => 'TEXT',
                             'UN' => 'UNKNOWN',
                             'VI' => 'VIDEO',
                           );
    self::$majorMimes    = array
                           (
                             'AP' => 'application',
                             'AU' => 'audio',
                             'IM' => 'image',
                             'ME' => 'message',
                             'MO' => 'model',
                             'MU' => 'multipart',
                             'TE' => 'text',
                             'VI' => 'video',
                             'UN' => 'unknown',
                           );
    self::$fileWhiteList = array
                           (
                             'image/jpg',
                             'image/jpeg',
                             'image/pjpeg',
                             'image/gif',
                             'image/png',
                             'image/x-png',
                             'application/pdf',
                             'application/x-pdf',
                           );
    self::$fileBlackList = array
                           (
	                         # HTML may contain cookie-stealing JavaScript and web bugs
	                         'text/html', 'text/javascript', 'text/x-javascript',  'application/x-shellscript',
	                         # PHP scripts may execute arbitrary code on the server
	                         'application/x-php', 'text/x-php',
	                         # Other types that may be interpreted by some servers
	                         'text/x-python', 'text/x-perl', 'text/x-bash', 'text/x-sh', 'text/x-csh',
	                         # Windows metafile, client-side vulnerability on some systems
	                         'application/x-msmetafile'
                           );
    self::$imageMimeTypeList = array
                               (
                                 'image/jpg',
                                 'image/jpeg',
                                 'image/pjpeg',
                                 'image/gif',
                                 'image/png',
                                 'image/x-png',
                               );
                           
    self::$wellKnownMimeTypes = <<<END_STRING
                                  application/ogg ogg ogm ogv
                                  application/pdf pdf
                                  application/x-javascript js
                                  application/x-shockwave-flash swf
                                  audio/midi mid midi kar
                                  audio/mpeg mpga mpa mp2 mp3
                                  audio/x-aiff aif aiff aifc
                                  audio/x-wav wav
                                  audio/ogg ogg
                                  image/x-bmp bmp
                                  image/gif gif
                                  image/jpeg jpeg jpg jpe
                                  image/png png
                                  image/svg+xml image/svg svg
                                  image/tiff tiff tif
                                  image/vnd.djvu image/x.djvu image/x-djvu djvu
                                  image/x-portable-pixmap ppm
                                  image/x-xcf xcf
                                  text/plain txt
                                  text/html html htm
                                  video/ogg ogm ogg ogv
                                  video/mpeg mpg mpeg
END_STRING;
    self::$wellKnownMimeInfo  = <<<END_STRING
                                  application/pdf [OFFICE]
                                  text/javascript application/x-javascript [EXECUTABLE]
                                  application/x-shockwave-flash [MULTIMEDIA]
                                  audio/midi [AUDIO]
                                  audio/x-aiff [AUDIO]
                                  audio/x-wav [AUDIO]
                                  audio/mp3 audio/mpeg [AUDIO]
                                  application/ogg audio/ogg video/ogg [MULTIMEDIA]
                                  image/x-bmp image/bmp [BITMAP]
                                  image/gif [BITMAP]
                                  image/jpeg [BITMAP]
                                  image/png [BITMAP]
                                  image/svg+xml [DRAWING]
                                  image/tiff [BITMAP]
                                  image/vnd.djvu [BITMAP]
                                  image/x-xcf [BITMAP]
                                  image/x-portable-pixmap [BITMAP]
                                  text/plain [TEXT]
                                  text/html [TEXT]
                                  video/ogg [VIDEO]
                                  video/mpeg [VIDEO]
                                  unknown/unknown application/octet-stream application/x-empty [UNKNOWN]
END_STRING;
  }
    
  public static function getMediaTypes()
  {
  	return self::$mediaTypes; 
  }
    
  public static function getMajorMimes()
  {
  	return self::$majorMimes; 
  }
    
  public static function getFileWhiteList()
  {
  	return self::$fileWhiteList; 
  }
    
  public static function getFileBlackList()
  {
  	return self::$fileBlackList; 
  }
    
  public static function getImageMimeTypeList()
  {
  	return self::$imageMimeTypeList; 
  }
    
  public static function getWellKnownMimeTypes()
  {
  	return self::$wellKnownMimeTypes; 
  }
    
  public static function getWellKnownMimeInfo()
  {
  	return self::$wellKnownMimeInfo; 
  }
}
